package com.action;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSON;
import com.dao.UpdateUserDao;
@Controller
public class UpdateUserAction {
	@Autowired
	private UpdateUserDao updatePasswordDao;
	private String password; 
	
	public String preUpdate(){
		return "preUpdate";
	}
	
	public String update(){
		HttpServletResponse response = ServletActionContext.getResponse();
		HashMap<String, String> map = new HashMap<String, String>();
		try {
			updatePasswordDao.updateUserInfo(password);
			map.put("code", "EC001");
		} catch (Exception e) {
			map.put("code", "EC002");
		}
		
		try {
			String msg = JSON.toJSONString(map);
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().write(msg);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
}
